package tech.aistar.corejava.test;

import java.util.Scanner;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/7/27 0027
 */
public class StringproDEMO {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请你输入第一个String:");
        String first = sc.nextLine();

        System.out.println("请你输入迭戈String:");
        String two = sc.nextLine();

        common(first,two);
    }

    private static void common(String first, String two) {
        StringBuilder builder = new StringBuilder();

        //aaaaaaaabbbbbbbbbbbbccccccccc
        //ffffffffggggggggggaaaaaaa
        int len = first.length();

        int len1 = 0;

        for (int i = 0; i < len ; i++) {
            for (int j = i+1; j <=len ; j++) {
                String substring = first.substring(i,j);
                int length = substring.length();
                if(two.contains(substring) && length>len1){
                    builder.delete(0,builder.capacity());
                    builder.append(substring+"\t");
                    len1 = length;
                }else if(two.contains(substring) && length==len1){
                    builder.append(substring+"\t");
                }
            }
        }
        System.out.println(builder);
    }
}
